import {request} from "./request";

// 请求用户列表
function  userInfoRequest({query, pagenum, pagesize}) {
    return request({
    url: 'users',
    params: {
      query,
      pagenum,
      pagesize
    }
  })
}

// 更改用户状态
function putUserStatue({id, mg_state}) {
  return request({
    url: `/users/${id}/state/${mg_state}`,
    method: 'put'
  })
}

// 添加用户
function addUserRequest({username, password, email, mobile}) {
  return request({
    url: '/users',
    method: 'post',
    data: {
      username,
      password,
      email,
      mobile
    }
  })
}

// 查询用户
function queryUserById(id) {
  return request({
    url: `/users/${id}`
  })
}

// 更改用户信息
function changeUserInfo({id, email, mobile}) {
  return request({
    url: `/users/${id}`,
    method: 'put',
    data: {
      email,
      mobile
    }
  })
}

// 删除用户
function removeUserById(id) {
  return request({
    url: `/users/${id}`,
    method: 'delete'
  })
}

// 分配角色
function setRole(id, rid) {
  return request({
    url: `/users/${id}/role`,
    method: 'put',
    data: {
      rid
    }
  })
}

export {userInfoRequest, putUserStatue, addUserRequest, queryUserById, changeUserInfo, removeUserById, setRole}